﻿<%@ WebHandler Language="C#" Class="Apollo.Website.InitHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace Apollo.Website
{
    public class InitHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            
            Apollo.Application.ApplicationState currentState = Apollo.Application.Current.InitializeAsync();

            if (currentState == Apollo.Application.ApplicationState.None)
            {
                context.Response.Write("{ \"procent\": \"0\", \"message\": \"Failed to load. Please refresh\", \"state\": \"Failed\" }");
            }
            else if (currentState == Application.ApplicationState.Loaded)
            {
                context.Response.Write("{ \"procent\": \"100\", \"message\": \"Load complete\", \"state\": \"Complete\" }");
            }
            else {
                context.Response.Write("{ \"procent\": \""
                    + Apollo.Application.ProcentLoaded.ToString() + "\", \"message\": \""
                    + currentState.ToString() + "\", \"state\": \""
                    + currentState.ToString().ToLower() + "\" }");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}